home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / io / Serializable.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  4.9 KB  |  113 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)Serializable.java    1.12 98/06/29
  3.  *
  4.  * Copyright 1996-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.io;
  16.  
  17. /**
  18.  * Serializability of a class is enabled by the class implementing the
  19.  * java.io.Serializable interface. Classes that do not implement this
  20.  * interface will not have any of their state serialized or
  21.  * deserialized.  All subtypes of a serializable class are themselves
  22.  * serializable.  The serialization interface has no methods or fields
  23.  * and serves only to identify the semantics of being serializable. <p>
  24.  *
  25.  * To allow subtypes of non-serializable classes to be serialized, the
  26.  * subtype may assume responsibility for saving and restoring the
  27.  * state of the supertype's public, protected, and (if accessible)
  28.  * package fields.  The subtype may assume this responsibility only if
  29.  * the class it extends has an accessible no-arg constructor to
  30.  * initialize the class's state.  It is an error to declare a class
  31.  * Serializable in this case.  The error will be detected at runtime. <p>
  32.  *
  33.  * During deserialization, the fields of non-serializable classes will
  34.  * be initialized using the public or protected no-arg constructor of
  35.  * the class.  A no-arg constructor must be accessible to the subclass
  36.  * that is serializable.  The fields of serializable subclasses will
  37.  * be restored from the stream. <p>
  38.  *
  39.  * When traversing a graph, an object may be encountered that does not
  40.  * support the Serializable interface. In this case the
  41.  * NotSerializableException will be thrown and will identify the class
  42.  * of the non-serializable object. <p>
  43.  *
  44.  * Classes that require special handling during the serialization and deserialization
  45.  * process must implement special methods with these exact signatures: <p>
  46.  *
  47.  * <PRE>
  48.  * private void writeObject(java.io.ObjectOutputStream out)
  49.  *     throws IOException
  50.  * private void readObject(java.io.ObjectInputStream in)
  51.  *     throws IOException, ClassNotFoundException;
  52.  * </PRE><p>
  53.  
  54.  * The writeObject method is responsible for writing the state of the
  55.  * object for its particular class so that the corresponding
  56.  * readObject method can restore it.  The default mechanism for saving
  57.  * the Object's fields can be invoked by calling
  58.  * out.defaultWriteObject. The method does not need to concern
  59.  * itself with the state belonging to its superclasses or subclasses.
  60.  * State is saved by writing the individual fields to the
  61.  * ObjectOutputStream using the writeObject method or by using the
  62.  * methods for primitive data types supported by DataOutput. <p>
  63.  
  64.  * The readObject method is responsible for reading from the stream and restoring
  65.  * the classes fields. It may call in.defaultReadObject to invoke
  66.  * the default mechanism for restoring the object's non-static and non-transient
  67.  * fields.  The defaultReadObject method uses information in the stream to
  68.  * assign the fields of the object saved in the stream with the correspondingly
  69.  * named fields in the current object.  This handles the case when the class
  70.  * has evolved to add new fields. The method does not need to concern
  71.  * itself with the state belonging to its superclasses or subclasses.
  72.  * State is saved by writing the individual fields to the
  73.  * ObjectOutputStream using the writeObject method or by using the
  74.  * methods for primitive data types supported by DataOutput. <p>
  75.  *
  76.  * Serializable classes that need to designate an alternative object to be
  77.  * used when writing an object to the stream should implement this
  78.  * special method with the exact signature: <p>
  79.  *
  80.  * <PRE>
  81.  * ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
  82.  * </PRE><p>
  83.  *
  84.  * This writeReplace method is invoked by serialization if the method
  85.  * exists and it would be accessible from a method defined within the
  86.  * class of the object being serialized. Thus, the method can have private,
  87.  * protected and package-private access. Subclass access to this method
  88.  * follows java accessibility rules. <p>
  89.  *
  90.  * Classes that need to designate a replacement when an instance of it
  91.  * is read from the stream should implement this special method with the
  92.  * exact signatute.<p>
  93.  *
  94.  * <PRE>
  95.  * ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
  96.  * </PRE><p>
  97.  *
  98.  * This readResolve method follows the same invocation rules and
  99.  * accessibility rules as writeReplace.
  100.  *
  101.  * @author  unascribed
  102.  * @version 1.12, 06/29/98
  103.  * @see java.io.ObjectOutputStream
  104.  * @see java.io.ObjectInputStream
  105.  * @see java.io.ObjectOutput
  106.  * @see java.io.ObjectInput
  107.  * @see java.io.Externalizable
  108.  * @since   JDK1.1
  109.  */
  110. public interface Serializable {
  111.     static final long serialVersionUID = 1196656838076753133L;
  112. }
  113.